home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / LockEmUp / LockemUp.jar / LockemUp / BaseActor.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-03-05  |  3.0 KB  |  187 lines

  1. package LockemUp;
  2.  
  3. import com.siemens.mp.game.GraphicObjectManager;
  4. import com.siemens.mp.game.Sprite;
  5.  
  6. public class BaseActor {
  7.    private GraphicObjectManager gfxManager;
  8.    private int curAction;
  9.    private int totalActions;
  10.    private int frameCounter;
  11.    private int frameRate;
  12.    private int curFrame;
  13.    private int[] framesCountList;
  14.    private byte[][] animationPixels;
  15.    private byte[][] maskPixels;
  16.    private Sprite[] sprites;
  17.    private int xPos;
  18.    private int yPos;
  19.    private int width;
  20.    private int height;
  21.    private boolean isVisible;
  22.    private boolean isEndOfAction;
  23.    private boolean isRewind;
  24.    private boolean isPlaying;
  25.  
  26.    public BaseActor(GraphicObjectManager var1, int var2, int var3, int var4, boolean var5, boolean var6) {
  27.       this.gfxManager = var1;
  28.       this.totalActions = var2;
  29.       this.width = var3;
  30.       this.height = var4;
  31.       this.isRewind = var5;
  32.       this.isPlaying = var6;
  33.       this.frameRate = 0;
  34.       this.frameCounter = 0;
  35.       this.curAction = -1;
  36.       this.curFrame = 0;
  37.       this.isVisible = false;
  38.       this.framesCountList = new int[var2];
  39.       this.animationPixels = new byte[var2][];
  40.       this.maskPixels = new byte[var2][];
  41.       this.sprites = new Sprite[var2];
  42.    }
  43.  
  44.    public void Dispose() {
  45.       this.gfxManager.deleteObject(this.sprites[this.curAction]);
  46.  
  47.       for(int var1 = 0; var1 < this.totalActions; ++var1) {
  48.          this.animationPixels[var1] = null;
  49.          this.maskPixels[var1] = null;
  50.       }
  51.  
  52.       this.sprites = null;
  53.       this.framesCountList = null;
  54.    }
  55.  
  56.    public int appendAction(int var1, byte[] var2, byte[] var3, int var4) {
  57.       if (var1 >= this.totalActions) {
  58.          return 1;
  59.       } else {
  60.          this.animationPixels[var1] = var2;
  61.          this.maskPixels[var1] = var3;
  62.          this.framesCountList[var1] = var4;
  63.          this.sprites[var1] = new Sprite(this.animationPixels[var1], 0, this.width, this.height, this.maskPixels[var1], 0, var4);
  64.          this.gfxManager.addObject(this.sprites[var1]);
  65.          return 0;
  66.       }
  67.    }
  68.  
  69.    public void setVisible(boolean var1) {
  70.       this.isVisible = var1;
  71.       this.sprites[this.curAction].setVisible(this.isVisible);
  72.    }
  73.  
  74.    public void setActionCollisionBox(int var1, int var2, int var3, int var4, int var5) {
  75.       this.sprites[var1].setCollisionRectangle(var2, var3, var4, var5);
  76.    }
  77.  
  78.    public Sprite getCurSprite() {
  79.       return this.sprites[this.curAction];
  80.    }
  81.  
  82.    public boolean isCollidedWith(BaseActor var1) {
  83.       return this.sprites[this.curAction].isCollidingWith(var1.getCurSprite());
  84.    }
  85.  
  86.    public void setPosition(int var1, int var2) {
  87.       this.xPos = var1;
  88.       this.yPos = var2;
  89.    }
  90.  
  91.    public void setPositionX(int var1) {
  92.       this.xPos = var1;
  93.    }
  94.  
  95.    public void setPositionY(int var1) {
  96.       this.yPos = var1;
  97.    }
  98.  
  99.    public int getPositionX() {
  100.       return this.xPos;
  101.    }
  102.  
  103.    public int getPositionY() {
  104.       return this.yPos;
  105.    }
  106.  
  107.    public int getWidth() {
  108.       return this.width;
  109.    }
  110.  
  111.    public int getHeight() {
  112.       return this.height;
  113.    }
  114.  
  115.    public int getCurrentFrame() {
  116.       return this.curFrame;
  117.    }
  118.  
  119.    public int getCurrentTotalFrames() {
  120.       return this.framesCountList[this.curAction];
  121.    }
  122.  
  123.    public int getCurrentAction() {
  124.       return this.curAction;
  125.    }
  126.  
  127.    public int getTotalActions() {
  128.       return this.totalActions;
  129.    }
  130.  
  131.    public void setFrameRate(int var1) {
  132.       this.frameRate = var1;
  133.    }
  134.  
  135.    public int changeToNewAction(int var1) {
  136.       if (var1 >= this.totalActions) {
  137.          return 1;
  138.       } else {
  139.          if (this.curAction >= 0) {
  140.             this.setVisible(false);
  141.          }
  142.  
  143.          this.curAction = var1;
  144.          this.setVisible(true);
  145.          this.isEndOfAction = false;
  146.          this.curFrame = 0;
  147.          this.sprites[this.curAction].setFrame(this.curFrame);
  148.          return 0;
  149.       }
  150.    }
  151.  
  152.    public void setCurrentFrame(int var1) {
  153.       if (var1 < this.framesCountList[this.curAction]) {
  154.          this.curFrame = var1;
  155.          this.sprites[this.curAction].setFrame(this.curFrame);
  156.       }
  157.    }
  158.  
  159.    public boolean isAnimationEnd() {
  160.       return this.isEndOfAction;
  161.    }
  162.  
  163.    public void frameActor() {
  164.       if (this.isPlaying) {
  165.          if (this.frameCounter == this.frameRate) {
  166.             if (this.curFrame == this.framesCountList[this.curAction] - 1) {
  167.                if (this.isRewind) {
  168.                   this.curFrame = 0;
  169.                }
  170.  
  171.                this.isEndOfAction = true;
  172.             } else {
  173.                this.isEndOfAction = false;
  174.                ++this.curFrame;
  175.             }
  176.  
  177.             this.sprites[this.curAction].setFrame(this.curFrame);
  178.             this.frameCounter = 0;
  179.          } else {
  180.             ++this.frameCounter;
  181.          }
  182.       }
  183.  
  184.       this.sprites[this.curAction].setPosition(this.xPos >> 8, this.yPos >> 8);
  185.    }
  186. }
  187.